home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FLOWER_M
/
BEAR.C
Wrap
C/C++ Source or Header
|
1990-03-20
|
4KB
|
190 lines
/*
Flower Maker.c
Copyright 1990 Josh Pritikin
Public Domain!
3.14.90 Finished first draft (.9)
3.18.90 Added user interface (1.0)
3.20.90 Cleaned up a few bugs (1.1)
*/
#include "stdio.h"
#include "SANE.h"
double fact[10];
int form[10], width, height;
#define onerad (3.141592654/180)
#define maxradius 120
main()
{
WindowPtr window;
int i, family, scrap, factused;
char response[64];
InitGraf(&thePort);
printf("\n");
window = FrontWindow();
SetPort(window);
SetWTitle(window, "\pFlower Maker v1.0");
PenNormal();
SetOrigin(0,0);
width = window->portRect.right-window->portRect.left;
height = window->portRect.bottom-window->portRect.top-15;
family = 0;
printf("Flower Maker v1.1\nCopyright 1990 Josh Pritikin\nPublic Domain\n\n");
do {
printf("\nWhich equation template do you want to use?\n");
printf("1. sin(x)\n");
printf("2. cos(x)\n");
printf("3. sin(x)+cos(x)\n");
printf("4. sin(x)+sin(x)\n");
printf("5. sin(x)+sin(x)+cos(x)\n");
printf("6. sin(x)+sin(x)+sin(x)\n");
printf("7. sin(x)+sin(x)+sin(x)+sin(x)\n");
printf("r. random\n");
printf("q. quit\n");
do {
if (family) printf("(%i):", family);
else printf("(r):");
i= 0;
do {
scanf("%c", &response[i]);
} while (response[i++] != '\n');
if (response[0] == 'q') goto exit;
} while (nbtwn(response[0], '1', '7') && response[0] != 'r' &&
response[0] != '\n');
printf("\n");
if (btwn(response[0], '1', '7')) family = response[0] - '1' +1;
else if (response[0] == 'r') family = 0;
for (i=0; i < TickCount()%100; i++) /* pseudo-randomize */
scrap = Random();
switch(family)
{
case 0: printf("random\n"); break;
case 1: printf("r = sin(x1*x)\n"); form[0] = 0; break;
case 2: printf("r = cos(x1*x)\n"); form[0] = 1; break;
case 3: printf("r = sin(x1*x)+cos(x2*x)\n"); form[0] = 0; form[1] = 1; break;
case 4: printf("r = sin(x1*x)+sin(x2*x)\n"); form[0] = 0; form[1] = 0; break;
case 5: printf("r = sin(x1*x)+sin(x2*x)+cos(x3*x)\n");
form[0] = form[1] = 0;
form[2] = 1;
break;
case 6: printf("r = sin(x1*x)+sin(x2*x)+sin(x3*x)\n");
form[0] = form[1] = form[2] = 0;
break;
case 7: printf("r = sin(x1*x)+sin(x2*x)+sin(x3*x)+sin(x4*x)\n");
form[0] = form[1] = form[2] = 0;
break;
}
if (family)
{
factused = (family-1)/2+1;
for (i=0; i < factused; i++)
{
printf("enter x%i (%g):", i+1, fact[i]);
scanf("%lf", &fact[i]);
scanf("%c", response); /* dunno why this is nessesary */
}
}
else
{
factused = Rand(1, 4);
for (i=0; i <= factused; i++)
{
fact[i] = (double)Rand(1, 10000)/1000;
form[i] = 0;
}
}
EraseRect(&window->portRect);
printf("\n\nr = %g*(", (double)maxradius/factused);
for (i=0; i < factused-1; i++)
{
switch (form[i])
{
case 0: printf("sin(x*%g)+", fact[i]); break;
case 1: printf("cos(x*%g)+", fact[i]); break;
}
}
switch (form[factused-1])
{
case 0: printf("sin(x*%g))\n", fact[factused-1]); break;
case 1: printf("cos(x*%g))\n", fact[factused-1]); break;
}
printf("press the mouse buttton to stop ");
for(i=0; i < factused; i++) printf("*");
printf("\n");
ShowBear(factused, form, fact);
printf("press any key to continue");
scanf("%c", response);
} while (true);
exit: ;
}
ShowBear(int comp, int *type, double *values)
{
double theta = 0, mag = 0;
Boolean firsttime = true;
int i;
for (theta = 0; theta < 360*onerad; theta += onerad*30)
for (i=1; i <= comp; i++)
{
MoveTo(cos(theta)*(maxradius/comp)*i+width/2,
sin(theta)*(maxradius/comp)*i+height/2);
Line(0,0);
}
while (!Button())
{
mag = 0;
for (i=0; i < comp; i++)
{
switch(type[i])
{
case 0: mag += sin(values[i]*theta); break;
case 1: mag += cos(values[i]*theta); break;
}
}
mag *= maxradius/comp;
if (firsttime)
{
firsttime = false;
MoveTo(cos(theta)*mag+width/2, sin(theta)*mag+height/2);
}
else
LineTo(cos(theta)*mag+width/2, sin(theta)*mag+height/2);
theta += onerad*2;
}
}
Rand(int low, int high)
{
int dist, num;
dist = high-low+1;
num = Random()%dist;
num = Abs(num)+low;
return num;
}